package com.mysoft.gfyx.common.rpc.opensearch.dto;

import com.mysoft.gfyx.common.time.TimeService;
import com.mysoft.gfyx.common.time.impl.TimeServiceImpl;
import lombok.Data;

import java.text.SimpleDateFormat;
import java.util.Date;

@Data
public class RecommendedDeveloperRequestDto extends SearchBaseRequestDto {
    private String keyword;
    private String area_code;
    private String province_code;
    private String city_code;
    private String project_label;
    private String land_usage;
    private String fitment_fee_label;
    private String start_time;
    private String end_time;
    private int page;
    private int page_size;

    protected void setFilterByField(String field, String operatorType, Object value) {
        switch (field) {
            case "publish_time":
                TimeService timeService = new TimeServiceImpl();

                SimpleDateFormat normalFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date v = timeService.parseDateStr(value.toString());
                if ("ge".equals(operatorType) || "gt".equals(operatorType)) {
                    this.setStart_time(normalFormater.format(v));
                } else if ("le".equals(operatorType) || "lt".equals(operatorType)) {
                    this.setEnd_time(normalFormater.format(v));
                }
                break;
            case "province_code":
            case "city_code":
                if (value != null && !value.toString().equals("")) {
                    if (this.getArea_code() == null || this.getArea_code().equals("")) {
                        this.setArea_code(value.toString());
                    } else {
                        this.setArea_code(this.getArea_code() + "," + value);
                    }
                }

                break;
            default:
                this.dynamicSetProperty(field, value);
        }
    }
}
